﻿using System.Globalization;
using System.Text.Json.Serialization;
using System.Text.Json;

namespace Decoration.Api.Comm
{
    public class CustomDateTimeConverter : JsonConverter<DateTime>
    {
        public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            // Implement logic to read DateTime from JSON
            // This method is called when deserializing JSON
            return DateTime.TryParse(reader.GetString(), out var dateTime) ? dateTime : DateTime.Parse(reader.GetString(), CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
        }

        public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
        {
            // Implement logic to write DateTime to JSON
            // This method is called when serializing DateTime to JSON
            writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss"));
        }
    }
}
